package cn.iocoder.yudao.module.study.example.springStopWatch;

import cn.hutool.core.date.StopWatch;

/**
 * @Author cjc
 * @Date 2024/3/20 16:32
 * @Description: 优雅的打印代码运行耗时
 * @Version 1.0
 */
public class SpringStopWatchExample {


    public static void main(String[] args) throws InterruptedException{
        StopWatch sw = new StopWatch();
        sw.start("A");
        Thread.sleep(500);
        sw.stop();
        sw.start("B");
        Thread.sleep(300);
        sw.stop();
        sw.start("C");
        Thread.sleep(200);
        sw.stop();

        System.out.println("各任务执行耗时：" + sw.prettyPrint());
        System.out.println("总耗时（秒）：" + sw.getTotalTimeSeconds());
        System.out.println("简短的总耗时描述：" + sw.shortSummary());
        System.out.println("统计时间任务数量：" + sw.getTaskCount());
        System.out.println("最后一个任务TaskInfo对象的名称：" + sw.getLastTaskInfo().getTaskName());
    }
}
